package com.qf.controller;

import com.qf.pojo.Account;
import com.qf.pojo.Result;
import com.qf.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/*
 *@Description:
 *@author:刘哥
 *@Date:11:20 2022/7/22
 */
@RestController
@RequestMapping("/account")
public class AccountController {
    @Autowired
    private AccountService accountService;
    @RequestMapping("/addAccount")
    public Result addAccount(@RequestBody Account account){
        System.out.println("0123");
        try {
            accountService.addAccount(account);
            return new Result(true,null,"账户添加成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,null,"账户添加失败");
        }
    }
    @RequestMapping("/findAll")
    public Result findAccount(){
        try {
            List<Account> accountList = accountService.findAll();
            return new Result(true,accountList,"查询所有账户成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,null,"查询所有账户失败");
        }
    }
    @RequestMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        try {
            accountService.deleteById(id);
            return new Result(true,null,"账户删除成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,null,"账户删除失败");
        }
    }

}
